package com.zhouzi.zhaoyang.ui.activity

import android.widget.Toast
import androidx.recyclerview.widget.GridLayoutManager
import com.zhouzi.zhaoyang.R
import com.zhouzi.zhaoyang.adapter.rvadapter.PrintSettingsAdapter
import com.zhouzi.zhaoyang.base.BaseActivity
import com.zhouzi.zhaoyang.util.SPUtils
import com.zhouzi.zhaoyang.util.SPUtils.Companion.getInstance
import kotlinx.android.synthetic.main.print_settings_activity.*

class PrintSettingsActivity : BaseActivity() {

    override fun getLayoutId(): Int {
        return R.layout.print_settings_activity
    }

    var data = ArrayList<String>()
    override fun initView() {
        viewClick()
        setData()
        recyclerPrintSettings.layoutManager = GridLayoutManager(this, 3)
        val adapter = PrintSettingsAdapter(R.layout.recycler_item_print_settings, data)
        recyclerPrintSettings.adapter = adapter

    }

    override fun onStart() {
        var mode: Int = SPUtils.getInstance().getValue("cbPrintSettingsPrintMode", 1) as Int
        if (mode == 1) {
            rbOne.isChecked = true
        } else if (mode == 2){
            rbTwice.isChecked = true

        }
        super.onStart()

    }

    private fun setData() {

//        data.add("打印两联")
        data.add("交易打印")
        data.add("实收打印")
        data.add("优惠打印")
        data.add("退款打印")
        data.add("会员打印")
        data.add("押金打印")
        data.add("微信打印")
        data.add("支付宝打印")
        data.add("通用通打印")
    }

    private fun viewClick() {
        tvApBtn.setOnClickListener { finish() }

        rgPrintSettings.setOnCheckedChangeListener { radioGroup, i ->
            when (radioGroup.checkedRadioButtonId) {
                R.id.rbOne -> saveSettings(1)
                R.id.rbTwice -> saveSettings(2)
            }
        }

    }

    private fun saveSettings(i: Int) {
        getInstance().putValue("cbPrintSettingsPrintMode", i)
    }


}
